home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / LabelHTMLLink.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  4.1 KB  |  160 lines

  1. package symantec.itools.awt;
  2.  
  3.  
  4. import java.net.URL;
  5. import java.awt.Event;
  6. import java.awt.Container;
  7. import java.applet.*;
  8.  
  9.  
  10. /**
  11.  * Creates a text string that calls a URL address when clicked. An application
  12.  * or applet can change the label text string, but a user cannot edit it.
  13.  * <p>
  14.  * Use LabelHTMLLink whenever you want to create ôhotö text, that links to a 
  15.  * URL address when clicked.
  16.  * <p>
  17.  * @version 1.0, Nov 26, 1996
  18.  * @author Symantec
  19.  */
  20. public class LabelHTMLLink
  21.     extends LabelButton
  22. {
  23.     /**
  24.      * URL to show when the button is clicked.
  25.      */
  26.     protected URL url;
  27.     /**
  28.      * Applet context that shows the URL.
  29.      */
  30.     protected AppletContext context;
  31.     /**
  32.      * Frame specifier for showing a URL document in a browser or applet 
  33.      * viewer. It is interpreted as follows:
  34.      * <UL>
  35.      * <DT>"_self"  show document in the current frame</DT>
  36.      * <DT>"_parent"    show document in the parent frame</DT>
  37.      * <DT>"_top"   show document in the topmost frame</DT>
  38.      * <DT>"_blank" show document in a new unnamed toplevel window</DT>
  39.      * <DT>all others   show document in a new toplevel window with the given name</DT>
  40.      * </UL>
  41.      */
  42.     protected String frame;
  43.  
  44.     /**
  45.      * Constructs a default LabelHTMLLink.
  46.      */
  47.     public LabelHTMLLink()
  48.     {
  49.         frame = null;
  50.     }
  51.  
  52.     /**
  53.      * Returns the URL to show when the button is clicked.
  54.      * @see #setURL
  55.      */
  56.     public URL getURL()
  57.     {
  58.         return url;
  59.     }
  60.  
  61.     /**
  62.      * Sets the URL to show when the button is clicked.
  63.      * @param u the URL to show when the button is clicked
  64.      * @see #getURL
  65.      */
  66.     public void setURL(URL u)
  67.     {
  68.         url = u;
  69.         context = null;
  70.     }
  71.  
  72.     /**
  73.      * Sets the title displayed on the applet frame while showing
  74.      * the URL.
  75.      * @param f applet frame title
  76.      * @see #getFrame
  77.      */
  78.     public void setFrame(String f)
  79.     {
  80.         frame = f;
  81.     }
  82.  
  83.     /**
  84.      * Returns the title that is displayed on the applet frame while showing
  85.      * the URL.
  86.      * @see #setFrame
  87.      */
  88.     public String getFrame()
  89.     {
  90.         return frame;
  91.     }
  92.  
  93.     /**
  94.      * Handles internal actions for this component.
  95.      * This is a standard Java AWT method which usually gets called by the AWT
  96.      * method handleEvent() in response to receiving an ACTION_EVENT event. In those 
  97.      * cases the o parameter contains the value in the event's arg field.
  98.      * 
  99.      * @param event the event that caused this action
  100.      * @param what the action
  101.      * @return true if the action was handled
  102.      * @see java.awt.Component#handleEvent
  103.      */
  104.     public boolean action(Event event, Object what)
  105.     {
  106.         if (context != null)
  107.         {
  108.             if (frame == null || frame.length() == 0)
  109.                 context.showDocument(url);
  110.             else
  111.                 context.showDocument(url, frame);
  112.  
  113.             return true;
  114.         }
  115.  
  116.         return false;
  117.     }
  118.  
  119.     /**
  120.      * Ensures that this component is laid out properly, as needed.
  121.      * This is a standard Java AWT method which gets called by the AWT to 
  122.      * make sure this component and its subcomponents have a valid layout.
  123.      * If this component was made invalid with a call to invalidate(), then 
  124.      * it is laid out again.
  125.      * 
  126.      * It is overridden here to locate the applet containing this component.
  127.      *
  128.      * @see java.awt.Component#invalidate
  129.      */
  130.     public void validate()
  131.     {
  132.         // On validation, try to find the containing applet.  If we can find
  133.         // it, we don't bother doing the link...
  134.         Container c;
  135.  
  136.         c = getParent();
  137.  
  138.         while (c != null)
  139.         {
  140.             if (c instanceof Applet)
  141.             {
  142.                 setAppletContext(((Applet) c).getAppletContext());
  143.                 break;
  144.             }
  145.  
  146.             c = c.getParent();
  147.         }
  148.     }
  149.  
  150.     /**
  151.      * Sets the applet context to use for showing the URL.
  152.      * @param c the applet context
  153.      */
  154.     protected void setAppletContext(AppletContext c)
  155.     {
  156.         context = c;
  157.     }
  158. }
  159.  
  160.